package com.ruoyi.web.controller.reseller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.reseller.VsDramasResellerLog;
import com.ruoyi.system.service.reseller.IVsDramasResellerLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * This file is part of 南阳迈特网络科技有限公司.
 * @company  南阳迈特网络科技有限公司
 * @link     https://www.nymaite.com
 * @document https://product.nymaite.cn
 * @contact  service@nymaite.com
 * @author nymaite
 */
/**
 * 分佣记录Controller
 * 
 * @author zzx
 * @date 2024-04-27
 */
@Api(tags = "分佣记录")
@RestController
@RequestMapping("/reseller/log")
public class VsDramasResellerLogController extends BaseController
{
    @Autowired
    private IVsDramasResellerLogService vsDramasResellerLogService;

    /**
     * 查询分佣记录列表
     */
    @ApiOperation("查询分佣记录列表")
    @GetMapping("/list")
    public TableDataInfo list(VsDramasResellerLog vsDramasResellerLog)
    {
        if (getLoginUser().getDeptId() != null) {
            startPage();
            List<VsDramasResellerLog> list = vsDramasResellerLogService.selectVsDramasResellerLogList(vsDramasResellerLog);
            return getDataTable(list);
        }
        if (getLoginUser().getVsUser() == null) {
            TableDataInfo dataTable = new TableDataInfo();
            dataTable.setCode(500);
            dataTable.setMsg("请先登录");
            return dataTable;
        }
        if ("guest".equals(getLoginUser().getVsUser().getMode())) {
            TableDataInfo dataTable = new TableDataInfo();
            dataTable.setCode(500);
            dataTable.setMsg("请先登录");
            return dataTable;
        }
        vsDramasResellerLog.setResellerUserId(Math.toIntExact(getLoginUser().getVsUser().getId()));
        startPage();
        List<VsDramasResellerLog> list = vsDramasResellerLogService.selectVsDramasResellerLogList(vsDramasResellerLog);
        return getDataTable(list);
    }

    /**
     * 导出分佣记录列表
     */
//    @ApiOperation("导出分佣记录列表")
    @Log(title = "分佣记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VsDramasResellerLog vsDramasResellerLog)
    {
        List<VsDramasResellerLog> list = vsDramasResellerLogService.selectVsDramasResellerLogList(vsDramasResellerLog);
        ExcelUtil<VsDramasResellerLog> util = new ExcelUtil<VsDramasResellerLog>(VsDramasResellerLog.class);
        util.exportExcel(response, list, "分佣记录数据");
    }

    /**
     * 获取分佣记录详细信息
     */
    @ApiOperation("获取分佣记录详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(vsDramasResellerLogService.selectVsDramasResellerLogById(id));
    }

    /**
     * 新增分佣记录
     */
    @ApiOperation("新增分佣记录")
    @Log(title = "分佣记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VsDramasResellerLog vsDramasResellerLog)
    {
        return toAjax(vsDramasResellerLogService.insertVsDramasResellerLog(vsDramasResellerLog));
    }

    /**
     * 修改分佣记录
     */
//    @ApiOperation("修改分佣记录")
    @Log(title = "分佣记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VsDramasResellerLog vsDramasResellerLog)
    {
        return toAjax(vsDramasResellerLogService.updateVsDramasResellerLog(vsDramasResellerLog));
    }

    /**
     * 删除分佣记录
     */
//    @ApiOperation("删除分佣记录")
    @Log(title = "分佣记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(vsDramasResellerLogService.deleteVsDramasResellerLogByIds(ids));
    }

    @PostMapping("/selectCount")
    public AjaxResult selectCount(@RequestBody VsDramasResellerLog vsDramasResellerLog) {
        return AjaxResult.success(vsDramasResellerLogService.selectCount(vsDramasResellerLog));
    }
}
